package com.example.tests; 

import org.junit.*;
import static org.junit.Assert.*;

import com.example.common.SortedListOf;
import com.example.common.TestBase;
import com.example.common.User;
import com.example.pages.UsersPage;

public class RemoveUser extends TestBase {
    @Test
    public void testRemoveUser() throws Exception{
   
    	UsersPage userPage = goToMainPage().loginWithValidCredentials("admin",
				"admin").gotoUserManagementPage();

		int oldSize = userPage.getUserCount();
		SortedListOf<User> oldUserList = userPage.getUsers();
	
		int newSize;
		User user = new User().withName("user1").withEmail("user1@test.ru").withPassword("user1");
		if (!oldUserList.contains(user)) {
			userPage.createUser(user);
			oldUserList = userPage.getUsers();
			newSize = userPage.getUserCount();
			assertEquals(newSize, oldSize + 1);
		}
				
		userPage.deleteUser(user);
		SortedListOf<User> newUserList = userPage.getUsers();
		
		assertEquals(newUserList, oldUserList.without(user));
		
    	userPage.logout();
    }

     
}